package com.jimikongjian.service.dao.impl;

import com.jimikongjian.dao.IArticle;
import com.jimikongjian.dao.IArticleRoom;
import com.jimikongjian.models.ArticleRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fuxiuyang on 17-5-13.
 */
@Service("iArticleRoomImpl")
public class IArticleRoomImpl implements IArticleRoom {

    @Autowired
    private IArticleRoom iArticleRoom;

    /**
     * 通过id号，获取文章所属空间的信息
     *
     * @param id
     * @return List<ArticleRoom>
     */
    @Override
    public List<ArticleRoom> getArticleRoomListById(int id) {
        if (id > 0){
            return iArticleRoom.getArticleRoomListById(id);
        }
        return null;
    }

    /**
     * 插入一个新的文章到某一空间内
     *
     * @param articleRoom
     */
    @Override
    public void insertArticleRoom(ArticleRoom articleRoom) {
        if (articleRoom.getArticleId() > 0
                && articleRoom.getRoomId() > 0){
            iArticleRoom.insertArticleRoom(articleRoom);
        }

    }

    /**
     * 通过文章的id删除该文章内容
     *
     * @param articleRoom
     */
    @Override
    public void deleteByArticleId(ArticleRoom articleRoom) {
        if (articleRoom.getArticleId() > 0){
            iArticleRoom.deleteByArticleId(articleRoom);
        }
    }

    /**
     * 通过空间id删除该空间内的所有的文章，慎用该方法
     *
     * @param articleRoom
     */
    @Override
    public void deleteByRoomId(ArticleRoom articleRoom) {
        if (articleRoom.getRoomId() > 0){
            iArticleRoom.deleteByRoomId(articleRoom);
        }
    }

    /**
     * 通过空间id和文章id删除该空间内某一篇文章
     *
     * @param articleRoom
     */
    @Override
    public void deleteByRoomIdAndArticleId(ArticleRoom articleRoom) {
        if (articleRoom.getRoomId() > 0
                && articleRoom.getArticleId() > 0){
            iArticleRoom.deleteByRoomIdAndArticleId(articleRoom);
        }
    }
}
